package explorer
{
	import mx.events.FlexEvent;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	import smashedapples.core.Controller;

	public class AppController extends Controller
	{

		private function get view():AppView
		{
			return this.$view as AppView;
		}
		
		
		public function onCreationComplete( event:FlexEvent ):void
		{
			this.addListeners( [ "saveProduct", "searchProduct", "deleteProduct" ] ); 
		}
		
		
		public function onSaveProduct( event:AppEvent ):void
		{
			Debug.push( "AppController.onSaveProduct", event["data"] );
			view.model.datastore.save( "ProductVO",  event["data"] );
		}
		
		public function onSearchProduct( event:AppEvent ):void
		{
			Debug.push( "AppController.onSearchProduct", event["data"] );
			view.model.getProducts.send( event["data"] );
		}
		
		public function onDeleteProduct( event:AppEvent ):void
		{
			Debug.push( "AppController.onDeleteProduct", event["key"] );
			view.dataStoreScreen.productEntryForm.reset();
			view.model.datastore.Delete( "ProductVO", [ event["key"] ] );
		}
		
		
		private function fault( event:FaultEvent ):void
		{
			Debug.push( event, event.fault  );
		}
		
		private function result( event:ResultEvent ):void
		{
			Debug.push( event,  event.result );
		} 
		
	}
}